package com.xveshe.admin.service.impl;

import java.util.List;
import java.util.UUID;

import com.xveshe.admin.domain.XsglXsxx;
import com.xveshe.admin.mapper.XsglXsxxMapper;
import com.xveshe.common.utils.DateUtils;
import com.xveshe.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xveshe.admin.mapper.XsglGxsjMapper;
import com.xveshe.admin.domain.XsglGxsj;
import com.xveshe.admin.service.IXsglGxsjService;

/**
 * 岗训时间Service业务层处理
 *
 * @author geyasong
 * @date 2024-11-06
 */
@Service
public class XsglGxsjServiceImpl implements IXsglGxsjService
{
    @Autowired
    private XsglGxsjMapper xsglGxsjMapper;
    @Autowired
    private XsglXsxxMapper xsglXsxxMapper;

    /**
     * 查询岗训时间
     *
     * @param id 岗训时间主键
     * @return 岗训时间
     */
    @Override
    public XsglGxsj selectXsglGxsjById(String id)
    {

        return xsglGxsjMapper.selectXsglGxsjById(id);
    }

    /**
     * 查询岗训时间列表
     *
     * @param xsglGxsj 岗训时间
     * @return 岗训时间
     */
    @Override
    public List<XsglGxsj> selectXsglGxsjList(XsglGxsj xsglGxsj)
    {

        if(!(SecurityUtils.getUsername().equals("admin")||SecurityUtils.hasRole("guanli"))){
            XsglXsxx xsxx = new XsglXsxx();
            xsxx.setXsxxXsds(SecurityUtils.getUsername());
            xsxx.setXsxxQyds(SecurityUtils.getUsername());
            xsglGxsj.setGxsjXsmc(xsglXsxxMapper.selectXsglXsxx(xsxx).getId());
        }
        return xsglGxsjMapper.selectXsglGxsjList(xsglGxsj);
    }

    /**
     * 新增岗训时间
     *
     * @param xsglGxsj 岗训时间
     * @return 结果
     */
    @Override
    public int insertXsglGxsj(XsglGxsj xsglGxsj)
    {
        xsglGxsj.setId(UUID.randomUUID().toString());
        //获取用户账号xsglXslb.setCreator(SecurityUtils.getUsername());
        //获取用户昵称
        xsglGxsj.setCreator(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglGxsj.setCreatedate(DateUtils.getNowDate());
        return xsglGxsjMapper.insertXsglGxsj(xsglGxsj);
    }

    /**
     * 修改岗训时间
     *
     * @param xsglGxsj 岗训时间
     * @return 结果
     */
    @Override
    public int updateXsglGxsj(XsglGxsj xsglGxsj)
    {
        xsglGxsj.setLastmodifier(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglGxsj.setLastmodifieddate(DateUtils.getNowDate());
        return xsglGxsjMapper.updateXsglGxsj(xsglGxsj);
    }

    /**
     * 批量删除岗训时间
     *
     * @param ids 需要删除的岗训时间主键
     * @return 结果
     */
    @Override
    public int deleteXsglGxsjByIds(String[] ids)
    {
        return xsglGxsjMapper.deleteXsglGxsjByIds(ids);
    }

    /**
     * 删除岗训时间信息
     *
     * @param id 岗训时间主键
     * @return 结果
     */
    @Override
    public int deleteXsglGxsjById(String id)
    {
        return xsglGxsjMapper.deleteXsglGxsjById(id);
    }
}
